<template>
  <div class="app">
    <el-container>
      <el-aside width="200px">
        <main>
          <el-menu
            style="height:100%"
            :default-active="defaultActive"
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            :router="true"
            @select="selectClick"
          >

            <!-- <el-submenu index="1">
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>面试宝典</span>
              </template>
                <el-menu-item index="/msbd">面试宝典</el-menu-item>
                <el-menu-item index="/msbd/classify">类别管理 </el-menu-item>
            </el-submenu> -->
            <el-menu-item index="/">
              <i class="el-icon-odometer"></i>
              <span slot="title">仪表盘</span>
            </el-menu-item>
            <el-submenu index="1">
              <template slot="title">
                <i class="el-icon-s-management"></i>
                <span>知识库</span>
              </template>
              <el-menu-item-group>
                <el-menu-item index="/msbd">
                  <i class="el-icon-news"></i>
                  <span slot="title">面试宝典</span>
                </el-menu-item>
                <el-menu-item index="/msbd/classify">
                  <i class="el-icon-menu"></i>
                  <span slot="title">类别管理</span>
                </el-menu-item>
              </el-menu-item-group>
               
            </el-submenu>
            <el-submenu index="2">
              <template slot="title">
                <i class="el-icon-edit-outline"></i>
                <span>在线考试</span>
              </template>
              <el-menu-item-group>
                <el-menu-item index="/exam/study">
                  <i class="el-icon-reading"></i>
                  <span slot="title">学习模式</span>
                </el-menu-item>
                <el-menu-item index="/exam">
                  <i class="el-icon-alarm-clock"></i>
                  <span slot="title">考试模式</span>
                </el-menu-item>
                <el-menu-item index="/exam/question">
                  <i class="el-icon-collection"></i>
                  <span slot="title">题库管理</span>
                </el-menu-item>
              </el-menu-item-group>
               
            </el-submenu>
           
            <el-menu-item index="/user">
              <i class="el-icon-s-custom"></i>
              <span slot="title">用户管理</span>
            </el-menu-item>
            <!-- <el-submenu index="2">
              <template slot="title">
                <i class="el-icon-user"></i>
                <span>用户管理</span>
              </template>
                <el-menu-item index="/user">用户管理</el-menu-item>
            </el-submenu> -->
          </el-menu>
        </main>
      </el-aside>
      <el-container>
        <el-header class="container_hearder>">
          <h1>后台管理系统</h1>
          <el-dropdown @command="handleCommand">
            <span class="el-dropdown-link">
              用户:{{userInfo.name}}({{maps[userInfo.roles]}})<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command='personal'>个人中心</el-dropdown-item>
              <el-dropdown-item command="settings">系统设置</el-dropdown-item>
              <el-dropdown-item command='logout'>安全退出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-header>
        <el-main > 
          <Nuxt   />
        </el-main>
        <el-footer style="height:30px">Footer</el-footer>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import {mapGetters} from 'vuex'
export default {
  data(){
    return {
      maps:{
        admin:"管理员",
        editor:"编辑者",
        student:"学生"
      },
      defaultActive:"/"
    }
  },
  computed:{
    ...mapGetters(['userInfo'])
  },
  mounted(){
    this.defaultActive=localStorage.getItem("STATU")
    // console.log(this.defaultActive) 
  },

  methods:{
    async handleCommand(command){
      if(command=="logout"){
        await this.$store.dispatch("user/doLogout")
        this.$router.push("/login")
      }
    },
    selectClick(index){ 
      this.defaultActive=index
      localStorage.setItem("STATU",this.defaultActive)
    }
  }
};
</script>

<style>
html,
body,
#__nuxt,
#__layout,
.app
{
  height: 100%;
}
#__layout>div{
  height: 100%;
}
</style>
<style scoped>
.el-dropdown-link {
    cursor: pointer;
    color: #666;
  }
  .el-icon-arrow-down {
    font-size: 12px;
  }
  .el-dropdown {
      display: flex;
      align-items: center;
      position: relative;
      color: #606266;
      font-size: 14px;
  }
.user{
  border: 0;
  outline: none;
  background:  #ccc;
  color: #666;
}
.el-aside-header{
  height: 60px;
  background: #303133;
}
.el-menu{
      border-right: none;
}
  .el-container{
      height: 100%;
  }
 .el-header {
    background-color: #ccc;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
 
  .el-footer{
    background: #CCCCCC;
  }
  .el-aside {
    background-color: #545c64;
   
  }
  
  .el-main {
    background-color: #E9EEF3;
  }
  
  body > .el-container {
    margin-bottom: 40px;
  }
  
  /* .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }
  
  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  } */
</style>